
USE [BS7]
GO
/****** Object:  View [dbo].[VW_Vouchers]    Script Date: 07/13/2020 13:18:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[VW_Vouchers]
AS
SELECT     dbo.VoucherDetails.VoucherID, dbo.Voucher.VoucherDate, dbo.Voucher.VoucherNo, dbo.Voucher.SessionID, dbo.SessionInfo.SessionTitle, 
                      dbo.SessionInfo.SessionFrom, dbo.SessionInfo.SessionTo, dbo.SessionInfo.CurrentSession, dbo.Voucher.Remarks AS MasterRemarks, dbo.Voucher.ReadOnly, 
                      dbo.VoucherDetails.VoucherDetailID, dbo.VoucherDetails.AccountNo, dbo.Accounts.AccountTitle, dbo.VoucherDetails.Remarks, 
                      CASE WHEN (dbo.VoucherDetails.DrOrCr = N'Dr') THEN dbo.VoucherDetails.Amount ELSE - 1 * dbo.VoucherDetails.Amount END AS Amount, 
                      CASE WHEN (dbo.VoucherDetails.DrOrCr = N'Dr') THEN dbo.VoucherDetails.Amount ELSE 0 END AS Debit, CASE WHEN (dbo.VoucherDetails.DrOrCr = N'Cr') 
                      THEN dbo.VoucherDetails.Amount ELSE 0 END AS Credit, dbo.VoucherDetails.DrOrCr, dbo.Accounts.ParentAccount, dbo.Voucher.BankAccountID, 
                      Accounts_2.AccountTitle AS BankAccountTitle, Accounts_2.Remarks AS BankAddress, Accounts_2.CellNo AS BankCellNo, Accounts_2.Phone AS BankPhone, 
                      dbo.Voucher.LoginID, dbo.Employees.EmployeeName, dbo.Voucher.HostName, dbo.Voucher.EntryDateTime, dbo.VoucherDetails.Amount AS ActualAmount, 
                      dbo.Voucher.Amount AS VoucherAmount, dbo.Voucher.TotalAmount, dbo.Voucher.NetAmount, dbo.Voucher.Expense, dbo.Voucher.TotalAmount AS Expr1, 
                      dbo.Voucher.NetAmount AS Expr2, dbo.Voucher.Discount, dbo.Voucher.ModifyID, Employees_1.EmployeeName AS ModifyName, dbo.Voucher.ModifyHostName, 
                      dbo.Voucher.ModifyDateTime, dbo.VoucherDetails.ItemID, dbo.vw_Items.ItemCode, dbo.vw_Items.ItemName, dbo.vw_Items.ItemNameUrdu, dbo.vw_Items.UnitID, 
                      dbo.vw_Items.UnitName, dbo.vw_Items.UnitNameUrdu, dbo.VoucherDetails.Qty, dbo.VoucherDetails.Rate, dbo.VoucherDetails.Unit, dbo.vw_Items.GroupID, 
                      dbo.vw_Items.GroupName, dbo.Voucher.CustomerName, dbo.Accounts.Remarks AS AccountAddress, dbo.Accounts.CellNo, dbo.Accounts.Phone, 
                      dbo.Accounts.NameUrdu, dbo.Voucher.ReceiptNo, dbo.Voucher.DateDelivery, dbo.Voucher.Cash, dbo.Voucher.CustomerID, 
                      Accounts_1.AccountTitle AS CustomerIDName, Accounts_1.CellNo AS CustomerCellNo, Accounts_1.Phone AS CustomerPhone, 
                      Accounts_1.Remarks AS CustomerAddress, dbo.Voucher.ProjectCost, dbo.Voucher.RefVNo, dbo.VoucherDetails.ComboID, ISNULL(dbo.Combos.ComboCode, '') 
                      AS ComboCode, ISNULL(dbo.Combos.ComboName, '') AS ComboName, ISNULL(dbo.Combos.ComboNameUrdu, '') AS ComboNameUrdu
FROM         dbo.Combos RIGHT OUTER JOIN
                      dbo.VoucherDetails ON dbo.Combos.ComboID = dbo.VoucherDetails.ComboID LEFT OUTER JOIN
                      dbo.vw_Items ON dbo.VoucherDetails.ItemID = dbo.vw_Items.ItemID LEFT OUTER JOIN
                      dbo.Accounts ON dbo.VoucherDetails.AccountNo = dbo.Accounts.AccountNo LEFT OUTER JOIN
                      dbo.Employees AS Employees_1 RIGHT OUTER JOIN
                      dbo.Accounts AS Accounts_2 RIGHT OUTER JOIN
                      dbo.Accounts AS Accounts_1 RIGHT OUTER JOIN
                      dbo.Voucher ON Accounts_1.AccountNo = dbo.Voucher.CustomerID ON Accounts_2.AccountNo = dbo.Voucher.BankAccountID ON 
                      Employees_1.EmployeeID = dbo.Voucher.ModifyID LEFT OUTER JOIN
                      dbo.Employees ON dbo.Voucher.LoginID = dbo.Employees.EmployeeID ON dbo.VoucherDetails.VoucherID = dbo.Voucher.VoucherID LEFT OUTER JOIN
                      dbo.SessionInfo ON dbo.Voucher.SessionID = dbo.SessionInfo.SessionID

-------------------------------------------------------------------------------------

USE [BS7]
GO
/****** Object:  View [dbo].[vw_VouchersDetail]    Script Date: 07/13/2020 13:18:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[vw_VouchersDetail]
AS
SELECT     dbo.VoucherDetails.VoucherID, dbo.Voucher.VoucherNo, dbo.Voucher.VoucherDate, dbo.VoucherDetails.AccountNo, dbo.Accounts.AccountTitle, 
                      dbo.SessionInfo.SessionTitle, dbo.VoucherDetails.Remarks, dbo.VoucherDetails.Amount AS Debit, 0 AS Credit, dbo.VoucherDetails.DrOrCr, 
                      dbo.VoucherDetails.VoucherDetailID, dbo.Voucher.Remarks AS MasterRemarks, dbo.Voucher.SessionID, dbo.Accounts.ParentAccount, dbo.Voucher.BankAccountID, 
                      ISNULL(dbo.Voucher.CustomerName, '') AS CustomerName, dbo.Voucher.Expense, dbo.Voucher.Discount, dbo.VoucherDetails.ItemID, dbo.VoucherDetails.Qty, 
                      dbo.VoucherDetails.Qty AS InQty, 0 AS OutQty, dbo.VoucherDetails.Rate, dbo.VoucherDetails.Unit, dbo.VoucherDetails.ComboID, ISNULL(dbo.Combos.ComboName, '') 
                      AS ComboName
FROM         dbo.VoucherDetails LEFT OUTER JOIN
                      dbo.Combos ON dbo.VoucherDetails.ComboID = dbo.Combos.ComboID LEFT OUTER JOIN
                      dbo.Accounts ON dbo.VoucherDetails.AccountNo = dbo.Accounts.AccountNo LEFT OUTER JOIN
                      dbo.Voucher ON dbo.VoucherDetails.VoucherID = dbo.Voucher.VoucherID LEFT OUTER JOIN
                      dbo.SessionInfo ON dbo.Voucher.SessionID = dbo.SessionInfo.SessionID
WHERE     (dbo.VoucherDetails.DrOrCr = N'Dr')
UNION ALL
SELECT     VoucherDetails_1.VoucherID, Voucher_1.VoucherNo, Voucher_1.VoucherDate, VoucherDetails_1.AccountNo, Accounts_1.AccountTitle, SessionInfo_1.SessionTitle, 
                      VoucherDetails_1.Remarks, 0 AS Debit, VoucherDetails_1.Amount AS Credit, VoucherDetails_1.DrOrCr, VoucherDetails_1.VoucherDetailID, 
                      Voucher_1.Remarks AS MasterRemarks, Voucher_1.SessionID, Accounts_1.ParentAccount, Voucher_1.BankAccountID, ISNULL(Voucher_1.CustomerName, '') 
                      AS CustomerName, Voucher_1.Expense, Voucher_1.Discount, VoucherDetails_1.ItemID, VoucherDetails_1.Qty, 0 AS InQty, VoucherDetails_1.Qty AS OutQty, 
                      VoucherDetails_1.Rate, VoucherDetails_1.Unit, VoucherDetails_1.ComboID, ISNULL(Combos_1.ComboName, '') AS ComboName
FROM         dbo.VoucherDetails AS VoucherDetails_1 LEFT OUTER JOIN
                      dbo.Combos AS Combos_1 ON VoucherDetails_1.ComboID = Combos_1.ComboID LEFT OUTER JOIN
                      dbo.Accounts AS Accounts_1 ON VoucherDetails_1.AccountNo = Accounts_1.AccountNo LEFT OUTER JOIN
                      dbo.Voucher AS Voucher_1 ON VoucherDetails_1.VoucherID = Voucher_1.VoucherID LEFT OUTER JOIN
                      dbo.SessionInfo AS SessionInfo_1 ON Voucher_1.SessionID = SessionInfo_1.SessionID
WHERE     (VoucherDetails_1.DrOrCr = N'Cr')
